<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

if ( empty( $_GET['mod'] ) )
{
		$GLOBALS['_GET']['mod'] = "system";
}
define( "JIEQI_MODULE_NAME", $_GET['mod'] );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( $_GET['mod'] );
jieqi_checkpower( $jieqiPower[$_GET['mod']]['adminblock'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
jieqi_loadlang( "blocks", JIEQI_MODULE_NAME );
if ( !empty( $_REQUEST['id'] ) )
{
		include_once( JIEQI_ROOT_PATH."/class/blocks.php" );
		$blocks_handler =& jieqiblockshandler::getinstance( "JieqiBlocksHandler" );
		$block = $blocks_handler->get( $_REQUEST['id'] );
		if ( !is_object( $block ) )
		{
				jieqi_printfail( $jieqiLang['system']['block_not_exists'] );
		}
		$blockSet = array(
				"bid" => $block->getvar( "bid" ),
				"blockname" => $block->getvar( "blockname" ),
				"module" => $block->getvar( "modname" ),
				"filename" => $block->getvar( "filename", "n" ),
				"classname" => $block->getvar( "classname", "n" ),
				"side" => $block->getvar( "side", "n" ),
				"title" => $block->getvar( "title", "n" ),
				"vars" => $block->getvar( "vars", "n" ),
				"template" => $block->getvar( "template", "n" ),
				"contenttype" => $block->getvar( "contenttype", "n" ),
				"custom" => $block->getvar( "custom", "n" ),
				"publish" => $block->getvar( "publish", "n" ),
				"hasvars" => $block->getvar( "hasvars", "n" )
		);
}
else if ( !empty( $_REQUEST['configid'] ) )
{
		jieqi_includedb( );
		$query = jieqiqueryhandler::getinstance( "JieqiQueryHandler" );
		$GLOBALS['_REQUEST']['configid'] = intval( $_REQUEST['configid'] );
		$sql = "select * from ".jieqi_dbprefix( "system_blockconfigs" )." where id = '".jieqi_dbslashes( $_REQUEST['configid'] )."'";
		$res = $query->execute( $sql );
		$modconfig = $query->getobject( $res );
		if ( !is_object( $modconfig ) )
		{
				jieqi_printfail( $jieqiLang['system']['block_config_notexists'] );
		}
		unset( $jieqiBlocks );
		jieqi_getconfigs( $modconfig->getvar( "modules", "n" ), $modconfig->getvar( "file", "n" ), "jieqiBlocks" );
		if ( !isset( $jieqiBlocks[$_REQUEST['key']] ) )
		{
				jieqi_printfail( $jieqiLang['system']['block_not_exists'] );
		}
		$blockSet = $jieqiBlocks[$_REQUEST['key']];
}
else
{
		jieqi_printfail( LANG_ERROR_PARAMETER );
}
$modname = $blockSet['module'];
if ( $modname == "system" )
{
		include( JIEQI_ROOT_PATH."/blocks/".$blockSet['filename'].".php" );
}
else
{
		include( $jieqiModules[$modname]['path']."/blocks/".$blockSet['filename'].".php" );
}
$classname = $blockSet['classname'];
include_once( JIEQI_ROOT_PATH."/lib/template/template.php" );
$jieqiTpl =& jieqitpl::getinstance( );
$cblock = new $classname( $blockSet );
$cblock->updatecontent( );
jieqi_msgwin( LANG_DO_SUCCESS, sprintf( $jieqiLang['system']['block_edit_success'], jieqi_htmlstr( $blockSet['blockname'] ) ) );
?>
